package com.jy.wms.service;

import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.common.base.SucessException;
import com.jy.wms.dao.WmsSoEnclosureMapper;
import com.jy.wms.pojo.WmsSoEnclosure;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName: WmsSoEnclosureService.java
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author LH
 * @Date Tue Dec 26 14:04:29 GMT+08:00 2017
 */

@Service
public class WmsSoEnclosureService extends BaseService<WmsSoEnclosureMapper, WmsSoEnclosure> {

    /**
     * 根据poid 查询对应的附件列表（不分页）
     *
     * @param soid
     * @return
     */
    @BaseServiceDescribe(moduleName = "发运单附件管理", btnName = "查询发运订单附件列表")
    public List<WmsSoEnclosure> getListBySoid(String soid) throws ServiceException {
        try {
            return dao.getListBySoid(soid);
        } catch (Exception e) {
            throw new ServiceException("查询发运订单附件列表", e);
        }
    }

    /**
     * 插入一条记录（匹配有值的字段）
     *
     * @param entity 实体对象
     * @return int
     */
    @BaseServiceDescribe(moduleName = "发运订单附件管理", btnName = "新增发运订单附件")
    public void baseInsertSelective(WmsSoEnclosure entity) throws ServiceException, SucessException {
        entity.setId(UUIDUtils.uuid());
        Integer count = dao.baseInsertSelective(entity);
        if (count > 0) {
            throw new SucessException("新增发运订单附件");
        } else {
            throw new ServiceException("新增发运订单附件失败，未存入数据库");
        }
    }

    /**
     * 修改 （匹配有值的字段）
     *
     * @param entity 主键ID列表
     * @return int
     */
    @BaseServiceDescribe(moduleName = "发运订单附件管理", btnName = "修改发运订单附件")
    public void baseUpdateByPrimaryKeySelective(WmsSoEnclosure entity) throws SucessException, ServiceException {
        Integer count = dao.baseUpdateByPrimaryKeySelective(entity);
        if (count > 0) {
            throw new SucessException("修改发运订单附件成功");
        } else {
            throw new ServiceException("修改发运订单附件失败，为存入数据库");
        }
    }

    /**
     * 删除（根据ID 批量删除）
     *
     * @param idList 主键ID列表
     * @return int
     */
    @BaseServiceDescribe(moduleName = "发运订单附件管理", btnName = "批量删除发运订单附件")
    @Transactional
    public void baseDeleteBathPrimaryKeys(List<String> idList) throws ServiceException, SucessException {
        Integer count = dao.baseDeleteBathPrimaryKeys(idList);
        if (count == idList.size()) {
            throw new SucessException("删除发运订单附件成功");
        } else {
            throw new ServiceException("删除发运订单附件失败,未完全删除");
        }
    }


}
